<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class AdminBills extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$this->load->view('v_adminbills');
	}
	
	public function getbills()
	{
		$this->load->model('m_adminbills');
		
		$json = $this->m_adminbills->get_bills();
		
		$jsonObject = json_decode($json);
		
		$aaData = array();
		
		foreach($jsonObject->aaData as $row)
		{
			$row['7'] = '<a href="' . site_url('adminbills/delete/' . $row[0] . '/' . $row[1]) . '"><i class="icon-trash"></i></a>';
			$row['DT_RowId'] = $row[0] . ':' . $row[1];
			
			array_push($aaData, $row); 
		}
		
		$jsonObject->aaData = $aaData;
		
		echo json_encode($jsonObject);
	}
	
	public function delete($invoice, $vendor)
	{
		$this->load->model('m_adminbills');
		
		$this->m_adminbills->delete_invoice($invoice, $vendor);
		
		$this->load->view('v_adminbills');
	}
	
	public function edit()
	{
		$prevalue = $this->input->post("prevalue", TRUE);
		$value = $this->input->post("value", TRUE);
		$column_index = $this->input->post("column_index", TRUE);
		$row_id = $this->input->post("row_id", TRUE);
		
		$this->load->model('m_adminbills');
		
		switch($column_index)
		{
			case 0: $this->m_adminbills->set_invoice($value, $row_id); break;
			case 1: $this->m_adminbills->set_vendor($value, $row_id); break;
			case 2: $this->m_adminbills->set_customeraccount($value, $row_id); break;
			case 3: $this->m_adminbills->set_customername($value, $row_id); break;
			case 4: $this->m_adminbills->set_duedate($value, $row_id); break;
			case 5: $this->m_adminbills->set_amount($value, $row_id); break;
			case 6: $this->m_adminbills->set_status($value, $row_id); break;
		}

		echo $value;
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */